import { createRouter, createWebHistory } from 'vue-router'
import Login from '../views/Login.vue'
import Register from '../views/Register.vue'
import Dashboard from '../views/Dashboard.vue'
import DashboardHome from '../views/dashboard/Home.vue'
import ThreatIntel from '../views/dashboard/ThreatIntel.vue'
import ExtractIntel from '../views/dashboard/ExtractIntel.vue'
import KnowledgeGraph from '../views/dashboard/KnowledgeGraph.vue'
import TrustEvaluation from '../views/dashboard/TrustEvaluation.vue'
import ReportManagement from '../views/dashboard/ReportManagement.vue'
import ModelManager from '../views/dashboard/ModelManager.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/register',
      name: 'register',
      component: Register
    },
    {
      path: '/dashboard',
      component: Dashboard,
      meta: { requiresAuth: true },
      children: [
        {
          path: '',
          name: 'dashboard-home',
          component: DashboardHome
        },
        {
          path: 'intel',
          name: 'threat-intel',
          component: ThreatIntel
        },
        {
          path: 'extract',
          name: 'extract-intel',
          component: ExtractIntel
        },
        {
          path: 'graph',
          name: 'knowledge-graph',
          component: KnowledgeGraph
        },
        {
          path: 'reports',
          name: 'report-management',
          component: ReportManagement
        },
        {
          path: 'trust',
          name: 'trust-evaluation',
          component: TrustEvaluation
        },
        {
          path: 'models',
          name: 'model-manager',
          component: ModelManager
        }
      ]
    }
  ]
})

// 导航守卫
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token')
  
  if (to.meta.requiresAuth && !token) {
    next('/login')
  } else {
    next()
  }
})

export default router 